# -*- coding:utf-8 -*-
"""
author:tuhou
time:2023/5/20 23:31 
思路：
"""
import requests
import execjs
from urllib.parse import urlencode


with open('challenge1.js', "r") as f:
    js = f.read()
js = execjs.compile(js)

url = "https://match2023.yuanrenxue.cn/api/match2023/1"

headers = {
  'authority': 'match2023.yuanrenxue.cn',
  'accept': 'application/json, text/javascript, */*; q=0.01',
  'accept-language': 'zh-CN,zh;q=0.9',
  'cache-control': 'no-cache',
  'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  'origin': 'https://match2023.yuanrenxue.cn',
  'pragma': 'no-cache',
  'referer': 'https://match2023.yuanrenxue.cn/topic/1',
  'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': '"Windows"',
  'sec-fetch-dest': 'empty',
  'sec-fetch-mode': 'cors',
  'sec-fetch-site': 'same-origin',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
  'x-requested-with': 'XMLHttpRequest'
}

num = 0
for i in range(1, 6):
    data = urlencode(js.call('get_data', i))
    response = requests.post(url, headers=headers, data=data).json()
    for values in response['data']:
        value = values['value']
        num += int(value)
    print("第{}页-------目前总和为{}".format(i, num))
    
print(num)
